<template>
  <div class="login">
    <div class="login_info">
      <div class="login_title">
        <img src="../assets/img/logo.png" />
        <div class="logo_text">哇塞电影-注册</div>
      </div>

      <div class="login_from">
        <p>UserName</p>
        <el-input v-model="userName" placeholder="账号"></el-input>
        <p>PassWord</p>
        <el-input
          v-model="passWord"
          placeholder="密码"
          show-password
        ></el-input>

        <p>Check PassWord</p>
        <el-input
          v-model="checkPassWord"
          placeholder="确认密码"
          show-password
        ></el-input>
        <div style="padding-top:10px">
          <el-checkbox v-model="agree">
            我已同意“哇塞电影”用户注册协议
          </el-checkbox>

        </div>

        <div class="btn">
          <el-button class="login-form-button" type="primary" @click=" Register"
            >SIGN UP</el-button
          >
        </div>

        <div class="login_footer">
          <el-link :underline="false" class="rg" href=/login>
            已有账号？去登录
            <i class="el-icon-right"></i>
          </el-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Register } from "../api/user";

export default {
  data() {
    return {
      userName: "",
      passWord: "",
      checkPassWord: "",
      agree: false,
    };
  },
  methods: {
    //登录按钮
    Register() {
      if (this.userName.length < 6) {
        this.$message({
          message: "请输入不少于6位的用户名",
          type: "warning",
        });
        return;
      }
      if (this.agree == false) {
        this.$message({
          message: "请勾选我已同意“哇塞电影”用户协议",
          type: "warning",
        });
        return;
      }
      if (this.passWord !== this.checkPassWord) {
        this.$message({
          message: "您两次请输入的密码不同！",
          type: "warning",
        });
        return;
      }

      const registerInfo = {
        username: this.userName,
        password: this.passWord,
      };
      Register(registerInfo).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: res.msg,
            type: "success",
          });
          this.$router.push("/login");
        }
      });
    },
    // handleBack() {
    //   this.$router.go(-1);
    // },
  },
};
</script>

<style lang="scss" scoped>
//scoped是为了防止页面class名相互影响
.login {
  width: 100%;
  height: 100%;
  .login_info {
    width: 500px;
    margin: 50px auto;
    .login_title {
      height: 75px;
      img {
        width: 75px;
        height: 75px;
        float: left;
        margin-left: 20px;
      }
      .logo_text {
        float: left;
        line-height: 75px;
        font-size: 30px;
        font-weight: bold;
        margin-left: 50px;
      }
    }
    .login_from {
      line-height: 50px;
      font-size: 16px;
      color: #91949c;
      font-weight: bold;
      line-height: 50px;
    }
    .btn .login-form-button {
      width: 100%;
      height: 50px;
      margin-top: 25px;
      font-size: 16px;
      background: #5a84fd;
      font-weight: bold;
    }
    .login_footer {
      height: 50px;
      line-height: 50px;
      text-align: center;
      .rg {
        font-weight: bold;
        font-size: 16px;
        margin-top: 35px;
      }
    }
  }
}
</style>